package com.google.code.pdfbrick.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;

import com.google.code.pdfbrick.PDFBrick;

@SuppressWarnings("serial")
public class PDFBrickFrame extends JFrame {

	private final static int BUTTON_WIDTH=40;
	
	private final static int BUTTON_HEIGHT=20;
	
	private final JTabbedPane tabPane1 = new JTabbedPane();

	private final JPanel mergePanel = new JPanel();

	private final JPanel splitPanel = new JPanel();

	private final GridLayout gridLayout = new GridLayout(4, 1);
	
	private BorderLayout borderLayout=new BorderLayout();

	private JLabel label1 = new JLabel("      From :");

	private JLabel label2 = new JLabel("Merge To :");

	private JTextField textField1 = new JTextField();

	private JTextField textField2 = new JTextField();

	private JButton mergeBtn = new JButton("Merge");

	private JButton cancelBtn = new JButton("Cancel");
	
	private JTextArea logTextArea=new JTextArea();

	public PDFBrickFrame() {
		init();
		this.add(tabPane1);
	}

	public static void main(final String[] args) {
		GUIConsole.run(new PDFBrickFrame(), 400, 400, false);
	}

	private void init() {
		JPanel panel;		
		mergePanel.setLayout(gridLayout);
		
		panel=new JPanel(borderLayout);
		panel.add(BorderLayout.WEST,label1);
		panel.add(BorderLayout.CENTER,textField1);
		mergePanel.add(panel);
		
		borderLayout=new BorderLayout();
		panel=new JPanel(borderLayout);
		panel.add(BorderLayout.WEST,label2);
		panel.add(BorderLayout.CENTER,textField2);
		mergePanel.add(panel);
		
		panel=new JPanel(new GridLayout(1,1));
		logTextArea.setBorder(new LineBorder(Color.BLACK,1));
		panel.add(logTextArea);
		mergePanel.add(panel);
		
		panel=new JPanel();
		mergeBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PDFBrick brick = new PDFBrick();
				brick.merge(textField2.getText(), textField1.getText());
			}
		});
		mergeBtn.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
		cancelBtn.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
		panel.add(mergeBtn);
		panel.add(cancelBtn);		
		mergePanel.add(panel);
		
		tabPane1.addTab("Merge", mergePanel);
	}

}
